
/**
 * created on 2012-04-25
 * @author  qiujz
 * @version 1.0
 *
 * Copyright (c)  Founder Software (Suzhou) Co., Ltd.  2012
 *  All rights reserved.
 *
 * 
 * ================================================================
 * Change Revision
 * ---------------------------------------------------------------
 *    DATE                BY                   COMMENT
 * ---------------------------------------------------------------
 * 2012-04-25         qiujz                Create class
 * 
 *
 * ================================================================
 */
package com.qjz.controller
{
	import com.founder.framework.base.BaseController;
	import com.founder.framework.base.BaseModel;
	import com.founder.framework.common.FounderUtils;
	import com.founder.framework.interfaces.IControllerable;
	import com.qjz.common.CommonUtils;
	import com.qjz.entity.DataQueryParameter;
	import com.qjz.entity.StudentInfoQueryParameter;
	import com.qjz.model.ListenerModel;
	import com.qjz.model.StudentInfoModel;
	
	import flash.events.Event;
	
	import mx.collections.ArrayCollection;
	import mx.core.FlexGlobals;
	import mx.rpc.AsyncResponder;
	import mx.rpc.AsyncToken;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	import mx.rpc.remoting.RemoteObject;
	
	/**
	 * 页面控制器对象
	 * @author qiujz
	 */
	public class StudentInfoController extends BaseController implements IControllerable
	{
		/**
		 * 构造函数
		 * @param model
		 */
		public function StudentInfoController(model:StudentInfoModel)
		{
			super(model);

			_service=new RemoteObject();
			_service.destination="sims.studentInfoService";
			_service.endpoint=CommonUtils.getServer(CommonUtils.SIMS);
			_service.showBusyCursor=true;
		}

		/**
		 * 获取页面模型对象
		 * @return 模型对象 
		 */
		public function get model():StudentInfoModel
		{
			return _model as StudentInfoModel;
		}

	
		/**
		 * 取得远程对象查询实体的方法
		 * @return 远程对象查询实体的接口方法
		 */
		public function get getEntityOperation():Object
		{
			return _service.getStudentInfoByPrimaryKey;
		}

		/**
		 * 取得远程对象检索实体的方法
		 * @return 远程对象检索实体的接口方法
		 */
		public function get searchOperation():Object
		{
			return _service.searchStudentInfoList;
		}

		/**
		 * 取得远程对象新增实体的方法
		 * @return 远程对象新增实体的接口方法
		 */
		public function get insertOperation():Object
		{
			return _service.insertStudentInfo;
		}

		/**
		 * 取得远程对象修改实体的方法
		 * @return 远程对象修改实体的接口方法
		 */
		public function get modifyOperation():Object
		{
			return _service.updateStudentInfo;
		}

		/**
		 * 取得远程对象删除实体的方法
		 * @return 远程对象删除实体的接口方法
		 */
		public function get deleteOperation():Object
		{
			return _service.deleteStudentInfo;
		}

		/**
		 * 取得远程对象批量删除实体的方法
		 * @return 远程对象批量删除实体的接口方法
		 */
		public function get deleteBatchOperation():Object
		{
			return _service.deleteStudentInfoBatch;
		}
		
		public function getExcelData(paramter:DataQueryParameter):AsyncToken {
			var token:AsyncToken = _service.getExcelData.send(paramter);
			token.addResponder(new AsyncResponder(getExcelDataHandler, faultHandler, token));
			return token;
		}
		private function getExcelDataHandler(event:ResultEvent, token:AsyncToken = null):void {
			model.dataList = event.result as ArrayCollection;
			if(model.dataList != null)
				model.total=model.dataList.length;
			model.dispatchEvent(new Event("GET_EXCEL_DATA"));
		}
		
		public function synData(paramter:StudentInfoQueryParameter, list:ArrayCollection):AsyncToken {
			var token:AsyncToken = _service.synData.send(paramter, list);
			token.addResponder(new AsyncResponder(synDataHandler, faultHandler, token));
			return token;
		}
		private function synDataHandler(event:ResultEvent, token:AsyncToken = null):void {
			FounderUtils.alert("操作成功！", "成功", null, null, FounderUtils.successIcon);
			ListenerModel.getInstance().dispatchEvent(new Event(ListenerModel.UPLOADE_SUCCESS));
		}
		
		public function doExportData(paramter:StudentInfoQueryParameter):AsyncToken
		{
			var token:AsyncToken=_service.exportData.send(paramter);
			token.addResponder(new AsyncResponder(exportDataHandler, faultHandler, token));
			return token;
		}		
		private function exportDataHandler(event:ResultEvent, token:AsyncToken=null):void
		{
			var file:String=event.result as String;
			if (file != null && file.length > 0)
			{
				var indexOf:int=file.lastIndexOf("\\");
				var filePath:String=file.slice(0, indexOf);
				var fileName:String=file.slice(indexOf + 1, file.length);
				CommonUtils.getServerDowloadPath(CommonUtils.SIMS, filePath, fileName);
			}
		}
		
		public function getDistinctList():AsyncToken
		{
			var token:AsyncToken=_service.searchDistinctList.send();
			token.addResponder(new AsyncResponder(getDistinctListHandler, faultHandler, token));
			return token;
		}
		private function getDistinctListHandler(event:ResultEvent, token:AsyncToken=null):void
		{
			model.distinctList = event.result as ArrayCollection;
		}
		
		public function getBanJiList(school:String):AsyncToken
		{
			var token:AsyncToken=_service.searchBanJiList.send(school);
			token.addResponder(new AsyncResponder(getBanJiListHandler, faultHandler, token));
			return token;
		}
		private function getBanJiListHandler(event:ResultEvent, token:AsyncToken=null):void
		{
			model.banJiList = event.result as ArrayCollection;
		}
	}
}
